home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Communication / MacWebLint-1.013 / MacWebLint-Lib.pl < prev    next >
Text File  |  1996-02-05  |  9KB  |  303 lines

  1. #========================================================================
  2. # Function:    whine
  3. # Purpose:    Give a standard format whine:
  4. #            filename(line #): <message>
  5. #               The associative array `enabled' is used as a gating
  6. #               function, to suppress or enable each warning.  Every
  7. #               warning has an associated identifier, which is used to
  8. #               refer to the warning, and as the index into the hash.
  9. #========================================================================
  10. sub whine
  11. {
  12.    local($line, $id, @argv) = @_;
  13.    local($mstyle)        = $variable{'message-style'};
  14.  
  15. ## JS 2-4-96
  16. ## Added the following lines so that the results would be saved to a file
  17. ## this is nice for the mac version.
  18. ## The results file is saved in the same folder as MacWebLint
  19.    open (OUTFILE, ">>$gResults") || die "Cannot open gResults: $!\n";
  20.  
  21.    return unless $enabled{$id};
  22.    $exit_status = 1;
  23.  
  24. ## JS 12-6-95
  25. ## rewritten to output to a text file cause this is the way that
  26. ## I want it to work. this is the best way that I know how to do it.
  27.  
  28.   if ($mstyle eq 'terse') {
  29.       print "$filename:$line:$id\n";
  30.       print OUTFILE "$filename:$line:$id\n";
  31.    return; }
  32.    
  33.   if ($mstyle eq 'lint') {
  34.       (eval "print \"$filename($line): $message{$id}\n\"");
  35.       (eval "print OUTFILE \"$filename($line): $message{$id}\n\"");
  36.   return; }
  37.  
  38.   if ($mstyle eq 'short') {
  39.       (eval "print \"line $line: $message{$id}\n\"");
  40.       (eval "print OUTFILE \"line $line: $message{$id}\n\"");
  41.    return; }
  42.       
  43.    close (OUTFILE);
  44.  
  45. # JS 12-6-95
  46. #  commented this out because it is re-done above
  47. #   (print "$filename:$line:$id\n"), return             if $mstyle eq 'terse';
  48. #   (eval "print \"$filename($line): $message{$id}\n\""), return if $mstyle eq 'lint';
  49. #   (eval "print \"line $line: $message{$id}\n\""), return if $mstyle eq 'short';
  50.  
  51.    die "Unknown message style `$mstyle'\n";
  52. }
  53.  
  54. #========================================================================
  55. # Function:    GetConfigFile
  56. # Purpose:    Read user's configuration file, if such exists.
  57. #               If WEBLINTRC is set in user's environment, then read the
  58. #               file referenced, otherwise try for $HOME/.weblintrc.
  59. #========================================================================
  60. sub GetConfigFile
  61. {
  62.    local(*CONFIG);
  63.    local($filename);
  64.    local($arglist);
  65.    local($value);
  66.  
  67.  
  68. # JS 2-4-96
  69. # this is the config file for MacWebLint.
  70.    $filename = "MacWebLint.rc";
  71.    return unless -f $filename;
  72.  
  73.    open(CONFIG,"< $filename") || do
  74.    {
  75.       print WARNING "Unable to read config file `$filename': $!\n";
  76.       return 0;
  77.    };
  78.  
  79.    while (<CONFIG>)
  80.    {
  81.       s/#.*$//;
  82.       next if /^\s*$/o;
  83.  
  84.       #-- match keyword: process one or more argument -------------------
  85.       if (/^\s*(enable|disable|extension|ignore)\s+(.*)$/io)
  86.       {
  87.      $keyword = "\U$1";
  88.      $arglist = $2;
  89.      while ($arglist =~ /^\s*(\S+)/o)
  90.      {
  91.         $value = "\L$1";
  92.  
  93.         &enableWarning($1, 1) if $keyword eq 'ENABLE';
  94.  
  95.         &enableWarning($1, 0) if $keyword eq 'DISABLE';
  96.  
  97.         $ignore{"\U$1"} = 1 if $keyword eq 'IGNORE';
  98.  
  99.         &AddExtension("\L$1") if $keyword eq 'EXTENSION';
  100.  
  101.         $arglist = $';
  102.      }
  103.       }
  104.       elsif (/^\s*set\s+(\S+)\s*=\s*(.*)/)
  105.       {
  106.          # setting a weblint variable
  107.          if (defined $variable{$1})
  108.          {
  109.             $variable{$1} = $2;
  110.          }
  111.          else
  112.          {
  113.             print WARNING "Unknown variable `$1' in configuration file\n";
  114.          }
  115.       }
  116.    }
  117.  
  118.    close CONFIG;
  119.  
  120.    1;
  121. }
  122.  
  123. sub enableWarning
  124. {
  125.    local($id, $enabled) = @_;
  126.  
  127.  
  128.    if (! defined $enabled{$id})
  129.    {
  130.       print WARNING "$PROGRAM: unknown warning identifier \"$id\"\n";
  131.       return 0;
  132.    }
  133.  
  134.    $enabled{$id} = $enabled;
  135.  
  136.    #
  137.    # ensure consistency: if you just enabled upper-case,
  138.    # then we should make sure that lower-case is disabled
  139.    #
  140.    $enabled{'lower-case'} = 0 if $_ eq 'upper-case';
  141.    $enabled{'upper-case'} = 0 if $_ eq 'lower-case';
  142.    $enabled{'upper-case'} = $enabled{'lower-case'} = 0 if $_ eq 'mixed-case';
  143.  
  144.    return 1;
  145. }
  146.  
  147. #========================================================================
  148. # Function:    AddExtension
  149. # Purpose:    Extend the HTML understood.  Currently supported extensions:
  150. #            netscape  - the netscape extensions proposed by
  151. #                                   Netscape Communications, Inc.  See:
  152. #               http://www.netscape.com/home/services_docs/html-extensions.html
  153. #========================================================================
  154. sub AddExtension
  155. {
  156.    local($extension) = @_;
  157.  
  158.    if ($extension ne 'netscape' && $extension ne 'java')
  159.    {
  160.       warn "$PROGRAM: unknown extension `$extension' -- ignoring.\n";
  161.       return;
  162.    }
  163.  
  164.    #---------------------------------------------------------------------
  165.    # java extensions
  166.    #---------------------------------------------------------------------
  167.  
  168.    if ($extension eq 'java')
  169.    {
  170.       $legalElements .= '|'.$javaElements;
  171.       $pairElements  .= '|APPLET';
  172.  
  173.       &AddAttributes('APPLET', 'CODEBASE', 'CODE', 'ALT', 'NAME',
  174.                    'WIDTH', 'HEIGHT', 'ALIGN', 'VSPACE', 'HSPACE');
  175.       &AddAttributes('PARAM', 'NAME', 'VALUE');
  176.  
  177.       $requiredContext{'PARAM'} = 'APPLET';
  178.       $requiredAttributes{'APPLET'} = 'CODE|WIDTH|HEIGHT';
  179.       $requiredAttributes{'PARAM'} = 'NAME|VALUE';
  180.  
  181.       return;
  182.    }
  183.  
  184.    #---------------------------------------------------------------------
  185.    # netscape extensions
  186.    #---------------------------------------------------------------------
  187.  
  188.    #-- new element attributes for existing elements ---------------------
  189.  
  190.    &AddAttributes('ISINDEX',  'PROMPT');
  191.    &AddAttributes('HR',       'SIZE', 'WIDTH', 'ALIGN', 'NOSHADE');
  192.    &AddAttributes('UL',       'TYPE');
  193.    &AddAttributes('OL',       'TYPE', 'START');
  194.    &AddAttributes('LI',       'TYPE', 'VALUE');
  195.    &AddAttributes('IMG',      'BORDER', 'VSPACE', 'HSPACE', 'USEMAP');
  196.    &AddAttributes('BODY',     'BGCOLOR', 'TEXT', 'LINK', 'VLINK', 'ALINK');
  197.    &AddAttributes('TABLE',    'CELLSPACING', 'CELLPADDING');
  198.    &AddAttributes('TD',       'WIDTH');
  199.    &AddAttributes('TH',       'WIDTH');
  200.    &AddAttributes('FORM',     'ENCTYPE');
  201.  
  202.    #-- new elements -----------------------------------------------------
  203.  
  204.    $legalElements .= '|'.$netscapeElements;
  205.    $pairElements  .= '|BLINK|CENTER|FONT|NOBR|MAP';
  206.    &AddAttributes('FONT',     'SIZE');
  207.    &AddAttributes('BASEFONT', 'SIZE');
  208.    &AddAttributes('MAP',      'NAME');
  209.    &AddAttributes('AREA',     'SHAPE', 'COORDS', 'HREF', 'NOHREF');
  210.    $requiredContext{'AREA'} = 'MAP';
  211.    $requiredAttributes{'MAP'} = 'NAME';
  212.    $requiredAttributes{'AREA'} = 'COORDS';
  213. }
  214.  
  215. sub AddAttributes
  216. {
  217.    local($element,@attributes) = @_;
  218.    local($attr);
  219.  
  220.  
  221.    $attr = join('|', @attributes);
  222.    if (defined $validAttributes{$element})
  223.    {
  224.       $validAttributes{$element} .= "|$attr";
  225.    }
  226.    else
  227.    {
  228.       $validAttributes{$element} = "$attr";
  229.    }
  230. }
  231.  
  232. #========================================================================
  233. # Function:    ListWarnings()
  234. # Purpose:    List all supported warnings, with identifier, and
  235. #        whether the warning is enabled.
  236. #========================================================================
  237. sub ListWarnings
  238. {
  239.    local($id);
  240.    local($message);
  241.  
  242.  
  243.    foreach $id (sort keys %enabled)
  244.    {
  245.       ($message = $message{$id}) =~ s/\$argv\[\d+\]/.../g;
  246.       $message =~ s/\\"/"/g;
  247.       print WARNING "$id (", ($enabled{$id} ? "enabled" : "disabled"), ")\n";
  248.       print WARNING "    $message\n\n";
  249.    }
  250. }
  251.  
  252. sub PrintToDo
  253. {
  254.    die "$todo" unless defined $variable{'url-get'};
  255.    print "[grabbing weblint todo list - $ToDoURL]\n";
  256.    system("$variable{'url-get'} $ToDoURL");
  257. }
  258.  
  259. #========================================================================
  260. # Function:    wanted
  261. # Purpose:    This is called by &find() to determine whether a file
  262. #               is wanted.  We're looking for files, with the filename
  263. #               extension .html or .htm.
  264. #========================================================================
  265. #
  266. # JS - 2-4-96
  267. # I completely re-wrote this function so that it would work correctly
  268. # the way that I wanted it to work. I guess it changed between the 1.011
  269. # and this version to support more than one index.html filename. Unfortunately, 
  270. # it did not seem to work correctly on the Mac. While my version may not 
  271. # be the fastest, it seems to work, which is more important to me. :)
  272.  
  273. sub wanted
  274. {
  275.    local($foundIndex);
  276.  
  277.     if ( -d $name )
  278.     {
  279.         $foundIndex = 0;
  280.         foreach $legalIndex (@dirIndices)
  281.         {
  282.             if ( -f ("$name" . ":" . "$legalIndex") )
  283.             {
  284.                 $foundIndex=1;
  285.                 last;
  286.             }
  287.         }    
  288.         if (! $foundIndex)
  289.         {
  290.             &whine("$name", 'directory-index', "@dirIndices");
  291.         }
  292.     }
  293.  
  294.        /\.(html|htm)$/ &&        # valid filename extensions: .html .htm
  295.       -f $_ &&            # only looking for files
  296.       (!$opt_l || !-l $_) &&    # ignore symlinks if -l given
  297.       &WebLint($_,$name);    # check the file
  298. }
  299.  
  300. 1;
  301.  
  302.  
  303.